package com.link2room.ironhide.controller.api;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.dto.result.base.HotelBaseInfoDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.common.util.StringUtil;
import com.link2room.ironhide.dto.param.api.HotelsApiParamDto;
import com.link2room.ironhide.facade.IHotelApiFacadeService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by sss on 2016/11/1.
 */
@Api(tags = "酒店基础信息相关")
@RestController
@RequestMapping("/api/HotelBaseInfos")
public class HotelBaseInfoApiController {
    @Resource
    private IHotelApiFacadeService hotelApiFacadeService;


    @RequestMapping(method= RequestMethod.GET)
    public BaseResultDto HotelBaseInfoList(
            @RequestParam(value = "lhotelCode" ,required = false) String lhotelCode,
            @RequestParam(value = "city" ,required = false) Long city,
            @RequestParam(value = "brands" ,required = false) String brands
    ) throws Exception {
        HotelsApiParamDto hotelsApiParamDto=new HotelsApiParamDto();
        hotelsApiParamDto.setLhotelCode(lhotelCode);
        hotelsApiParamDto.setCity(city);
        if(StringUtil.isNotBlank(brands)){
            List<String> brandList=new ArrayList();
            String[] brandArr = brands.split(",");
            for(String brand:brandArr){
                brandList.add(brand);
            }
            hotelsApiParamDto.setBrands(brandList);
        }
        QueryResult<HotelBaseInfoDto> hotelBaseInfoResult = hotelApiFacadeService.getHotelBaseInfoList(hotelsApiParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(hotelBaseInfoResult);
        return l2rRs;
    }

    @RequestMapping(value = "/{id}",method= RequestMethod.GET)
    public BaseResultDto HotelBaseInfo(
            @PathVariable Long id
    )throws Exception{
        HotelsApiParamDto hotelsApiParamDto=new HotelsApiParamDto();
        hotelsApiParamDto.setId(id);
        HotelBaseInfoDto hotelBaseInfo = hotelApiFacadeService.getHotelBaseInfo(hotelsApiParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(hotelBaseInfo);
        return l2rRs;
    }

    @RequestMapping(value = "/HotelBaseInfo",method= RequestMethod.GET)
    public BaseResultDto HotelBaseInfo(
            @RequestParam(value = "lhotelCode") String lhotelCode
    )throws Exception{
        HotelsApiParamDto hotelsApiParamDto=new HotelsApiParamDto();
        hotelsApiParamDto.setLhotelCode(lhotelCode);
        HotelBaseInfoDto hotelBaseInfo = hotelApiFacadeService.getHotelBaseInfo(hotelsApiParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(hotelBaseInfo);
        return l2rRs;
    }
}
